/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cv4j.app.slice;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;

import com.cv4j.app.ResourceTable;
import com.cv4j.app.app.BaseAbilitySlice;
import com.cv4j.app.utill.PixelMapUtil;
import com.cv4j.core.datamodel.CV4JImage;
import com.cv4j.core.filters.face.BeautySkinFilter;
import com.cv4j.rxcv4j.RxImageData;

/**
 * 人脸磨皮
 *
 * @since 2021-05-18
 */
public class BeautySkinAbilitySlice extends BaseAbilitySlice {
    private Image originImage1; // 原图
    private Image image1; // 磨皮后图
    private Image originImage2; // 原图
    private Image image2; // 磨皮后图
    private RxImageData rxImageData1;
    private RxImageData rxImageData2;

    @Override
    protected int getUIContentLayoutId() {
        return ResourceTable.Layout_ability_beauty_skin;
    }

    @Override
    protected void initComponents(Intent intent) {
        initView();
    }

    private void initView() {
        originImage1 = (Image)findComponentById(ResourceTable.Id_origin_image1);
        image1 = (Image)findComponentById(ResourceTable.Id_image1);
        originImage2 = (Image)findComponentById(ResourceTable.Id_origin_image2);
        image2 = (Image)findComponentById(ResourceTable.Id_image2);
        originImage1.setPixelMap(ResourceTable.Media_test_beauty_skin1);
        originImage2.setPixelMap(ResourceTable.Media_test_beauty_skin2);
        BeautySkinFilter beautySkinFilter1 = new BeautySkinFilter();
        CV4JImage cv4Jimage1 = new CV4JImage(PixelMapUtil.getPixelMapFromResource(
            getContext(),ResourceTable.Media_test_beauty_skin1).get());
        CV4JImage cv4Jimage2 = new CV4JImage(PixelMapUtil.getPixelMapFromResource(
            getContext(),ResourceTable.Media_test_beauty_skin2).get());
        rxImageData1 = new RxImageData(cv4Jimage1);
        rxImageData1.addFilter(beautySkinFilter1).into(image1);
        rxImageData2 = new RxImageData(cv4Jimage2);
        rxImageData2.addFilter(beautySkinFilter1).into(image2);
    }
}